package com.zikao.question.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.zikao.common.vo.TableListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.zikao.question.entity.Tag2Entity;
import com.zikao.question.service.Tag2Service;
import com.zikao.common.utils.PageUtils;
import com.zikao.common.utils.R;



/**
 * 
 *
 * @author likaisheng
 * @email 1805318928@qq.com
 * @date 2021-03-03 20:45:59
 */
@Controller
@RequestMapping("question/tag2")
public class Tag2Controller {
    @Autowired
    private Tag2Service tag2Service;

    /**
     * 查出所有标签
     */
    @RequestMapping("/all")
    @ResponseBody
    public R all(@RequestParam Map<String, Object> params){
        List<Tag2Entity> all = tag2Service.selectByMap(params);
        return R.ok().put("items", all);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tag2Service.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/listForLayUI")
    @ResponseBody
    public TableListVo listForLayUI(@RequestParam Map<String, Object> params){
        PageUtils page = tag2Service.queryPage(params);
        TableListVo<Tag2Entity> tableListVo = new TableListVo();

        tableListVo.setCode(0);
        tableListVo.setMsg("");
        tableListVo.setCount(page.getTotalCount());

        List<Tag2Entity> tagList = (List<Tag2Entity>) page.getList();
        tableListVo.setData(tagList);
        return tableListVo;
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") Long id){
		Tag2Entity tag2 = tag2Service.getById(id);

        return R.ok().put("tag2", tag2);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody Tag2Entity tag2){
		tag2Service.save(tag2);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody Tag2Entity tag2){
		tag2Service.updateById(tag2);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody Long[] ids){
		tag2Service.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
